package com.ruoyi.sys.vehile.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sys.vehile.domain.TbParking;
import com.ruoyi.sys.vehile.service.ITbParkingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 停车记录
 Controller
 *
 * @author ruoyi
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/system/parking")
public class TbParkingController extends BaseController
{
    @Autowired
    private ITbParkingService tbParkingService;

    /**
     * 查询停车记录
     列表
     */
    @PreAuthorize("@ss.hasPermi('system:parking:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbParking tbParking)
    {
        startPage();
        List<TbParking> list = tbParkingService.selectTbParkingList(tbParking);
        return getDataTable(list);
    }

    /**
     * 导出停车记录
     列表
     */

    @PreAuthorize("@ss.hasPermi('system:parking:export')")
    @Log(title = "停车记录 ", businessType = BusinessType.EXPORT)
            @PostMapping("/export")
            public void export(HttpServletResponse response, TbParking tbParking)
    {
        List<TbParking> list = tbParkingService.selectTbParkingList(tbParking);
        ExcelUtil<TbParking> util = new ExcelUtil<TbParking>(TbParking.class);
        util.exportExcel(response, list, "停车记录数据");
    }

    /**
     * 获取停车记录
     详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:parking:query')")
    @GetMapping(value = "/{pId}")
    public AjaxResult getInfo(@PathVariable("pId") Long pId)
    {
        return AjaxResult.success(tbParkingService.selectTbParkingByPId(pId));
    }

    /**
     * 新增停车记录

     */
    @PreAuthorize("@ss.hasPermi('system:parking:add')")
    @Log(title = "停车记录 ", businessType = BusinessType.INSERT)
            @PostMapping
            public AjaxResult add(@RequestBody TbParking tbParking)
            {
            return toAjax(tbParkingService.insertTbParking(tbParking));
            }

            /**
             * 修改停车记录

            */
            @PreAuthorize("@ss.hasPermi('system:parking:edit')")
            @Log(title = "停车记录 ", businessType = BusinessType.UPDATE)
            @PutMapping
            public AjaxResult edit(@RequestBody TbParking tbParking)
            {
            return toAjax(tbParkingService.updateTbParking(tbParking));
            }

            /**
             * 删除停车记录

            */
            @PreAuthorize("@ss.hasPermi('system:parking:remove')")
            @Log(title = "停车记录 ", businessType = BusinessType.DELETE)
            @DeleteMapping("/{pIds}")
            public AjaxResult remove(@PathVariable Long[] pIds)
    {
        return toAjax(tbParkingService.deleteTbParkingByPIds(pIds));
    }
}
